package design.singleton;

/**
 * <p>
 * 双重校验锁实现单例模式（JDK1.5以上）：
 * 延迟加载
 * 线程安全
 * 效率高
 * 实现困难
 *
 * </P>
 *
 * @author dingwen
 * @date 2021.10.14 16:15
 */
public class Singleton4 {
    private volatile static Singleton4 instance;

    private Singleton4() {
    }

    public static synchronized Singleton4 getInstance() {
        if (instance == null) {
            synchronized (Singleton4.class) {
                if (instance == null) {
                    instance = new Singleton4();
                }
            }
        }
        return instance;
    }
}
